/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.kamai.client.control;


import com.edu.kamai.webservice.client.WSPaperClient;
import com.edu.kamai.webservice.paper.Paper;
import java.util.List;

/**
 *
 * @author xyzhu
 */
public class paperControl {
    private static List<String> netList;
    private static String message;
    private static WSPaperClient wsPaperClient;
    
    public static String getMessage() {
        return message;
    }

    public static void setMessage(String message) {
        paperControl.message = message;
    }
        
    public static List<String> getNetList() {
        return netList;
    }

    public static void setNetList(List<String> l) {
        netList = l;
    }
    
    public static void setServer(){
        try{
            wsPaperClient = new WSPaperClient();
            
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
    
    public static int addOnePaper(String paperPath,String paperKey,
            String paperTitle,String paperDes,int paperRole){
        int ans;
        
        try{
            ans = wsPaperClient.addOnePaper(paperPath, paperKey, paperTitle, 
                    paperDes, paperRole);
            if (ans == 1) {
                message = "Add Paper OK!";
            } else {
                message = "Add Paper Failed!";
            }
            
        }catch(Exception ex){
            ans = 0;
            message = "Connect Server Error!";
            ex.printStackTrace();
        }
    
        return ans;

    }
    
    public static List<Paper> findPaperByRoleID(int roleID){
        List<Paper> papers=null;
        try{
            papers = wsPaperClient.findPaperByRoleID(roleID);
            if(papers.isEmpty() || papers == null){
                message = "no papers!";
            }else{
                message = "all " + papers.size() + " papers";
            }
        }catch(Exception ex){
            message = "Connect Server Error!";
            ex.printStackTrace();
        }
        return papers;
    }
    
    public static List<Paper> findPapers(){
        List<Paper> papers=null;
        try{
            papers = wsPaperClient.findPapers();
            if(papers.isEmpty() || papers == null){
                message = "no papers!";
            }else{
                message = "all " + papers.size() + " papers";
            }
        }catch(Exception ex){
            message = "Connect Server Error!";
            ex.printStackTrace();
        }
        return papers;
    }
    
    public static Paper findPaperByIDAndRole(int roleID,int pid){
        Paper paper = null;
        try{
            paper = wsPaperClient.findPaperByIDAndRole(roleID, pid);
            if(paper == null){
                message = "no paper!";
            }else{
                message = "get paper ok!";
            }
        }catch(Exception ex){
            message = "Connect Server Error!";
            ex.printStackTrace();
        }
        return paper;
    }
    
}
